package com.aaa.mbs.service.impl;

import com.aaa.common.util.Result;
import com.aaa.mbs.dao.MemberLevelDao;
import com.aaa.mbs.entity.MemberLevel;
import com.aaa.mbs.service.MemberLevelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (MemberLevel)表服务实现类
 *
 * @author yuxiujie
 * @since 2021-01-23 10:17:20
 */
@Service("memberLevelService")
public class MemberLevelServiceImpl implements MemberLevelService {
    @Resource
    private MemberLevelDao memberLevelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public MemberLevel queryById(Long id) {
        return this.memberLevelDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<MemberLevel> queryAllByLimit(int offset, int limit) {
        return this.memberLevelDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param memberLevel 实例对象
     * @return 实例对象
     */
    @Override
    public MemberLevel insert(MemberLevel memberLevel) {
        int i = memberLevelDao.count(memberLevel);
        if(i>0){
            return null;
        }
        this.memberLevelDao.insert(memberLevel);
        return memberLevel;
    }

    /**
     * 修改数据
     *
     * @param memberLevel 实例对象
     * @return 实例对象
     */
    @Override
    public MemberLevel update(MemberLevel memberLevel) {
        int count = memberLevelDao.count(memberLevel);
        if(count>0){
            return null;
        }
        this.memberLevelDao.update(memberLevel);
        return this.queryById(memberLevel.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        if(memberLevelDao.checkMember(id)>0){
            return false;
        }
        return this.memberLevelDao.deleteById(id) > 0;
    }

    /**
     * 分页查询多条数据
     *
     * @param memberLevel MemberLevel
     * @return 对象列表
     */
    @Override
    public PageInfo<MemberLevel> queryAll(int pageNo, int pageSize, MemberLevel memberLevel) {
        PageHelper.startPage(pageNo, pageSize);
        return new PageInfo<>(this.memberLevelDao.queryAll(memberLevel));
    }

}